package cn.seecoder.courselearning.controller.question;

import cn.seecoder.courselearning.dto.question.QuestionInfoDTO;
import cn.seecoder.courselearning.dto.question.QuestionWithAnalysisDTO;
import cn.seecoder.courselearning.service.question.QuestionService;
import cn.seecoder.courselearning.vo.ResultVO;
import cn.seecoder.courselearning.vo.course.CourseVO;
import cn.seecoder.courselearning.vo.question.QuestionVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/question")
public class QuestionController {
    @Resource
    private QuestionService questionService;

    /*
     * 利用从前端传来的QuestionVO来添加一道问题
     */
    @PostMapping("/create")
    public ResultVO<QuestionVO> createQuestion(@RequestBody QuestionVO question) {
        //System.out.println(question);
        System.out.println("QuestionController.createQuestion()");
        return questionService.createQuestion(question);
    }


    /*
     * 教师添加题目时根据quesion id返回对应题目的信息
     */
    @GetMapping("/qid/{questionId}")
    public ResultVO<QuestionVO> getQuestion(@PathVariable Integer questionId) {
        //int id = Integer.getInteger(questionId);
        System.out.println(questionId);
        System.out.println("QuestionController.getQuestion()");
        return questionService.getQuestion(questionId);
    }

    @GetMapping("/getAll")
    public List<QuestionVO> getAllQuestion(){
        System.out.println("QuestionController.getAllQuestion()");
        return questionService.getAllquestion();
    }


    /*
     * 教师在为某个课程创建测试时，返回一个列表，其中包含了该课程的所有题目
     */
    @GetMapping("/cid/{courseId}")
    public List<QuestionVO> getQuestionByCourseId(@PathVariable Integer courseId) {
        System.out.println("QuestionController.getQuestionByCourseId()");
        System.out.println(courseId);
        return questionService.getQuestionByCourseId(courseId);
    }
}
